package top.aicey.ai.sparring.common.utils;

import com.google.common.collect.Lists;
import org.springframework.util.AntPathMatcher;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class IgnoreUtils {


    private static List<String> includePaths = Lists.newArrayList(
            "/v3/sparing/list",
            "/v3/sparing/qa-pair",
            "/v3/sparing/init/qa-pair",
            "/v3/sparing/user-input/log",
            "/v3/sparing/ai-output/log",
            "/v3/sparing/end-handle",
            "/v3/sparing/test/**",
            "/doc.html",
            "/webjars/**",
            "/swagger-resources",
            "/error",
            "/v3/ai/ali/agent/callback"
    );

    private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();

    public static boolean checkIgnore(HttpServletRequest request) {
        // 特定的接口放过去  目前放过去课程翻译的回调
        String requestURI = request.getRequestURI();
        if (whitelistHandler(requestURI)) {
            return true;
        }
        return false;
    }

    private static boolean whitelistHandler(String path) {
        for (String pattern : includePaths) {
            if (ANT_PATH_MATCHER.match(pattern, path)) {
                return true;
            }
        }
        return false;
    }
}
